<template>
  <a-card :bordered="false" title="报告下载">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="14" :sm="24"> 
               <a-form-item label="申请日期">
                <j-date
                  placeholder="请选择开始日期"
                  class="query-group-cust"
                  v-model="queryParam.calcDate_begin"
                ></j-date>
                <span class="query-group-split-cust"></span>
                <j-date
                  placeholder="请选择结束日期"
                  class="query-group-cust"
                  v-model="queryParam.calcDate_end"
                ></j-date> 
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-button type="primary" @click="searchQuery">查询</a-button>
            <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-icon v-else  type="download"  @click="downloadFile(text)" title="下载报表"/>
          <!-- <a-button v-else :ghost="true" type="primary" title="下载报表" icon="download" size="small" @click="downloadFile(text)"/> -->
        </template>
      </a-table>
    </div>

    <report-cron-job-data-modal ref="modalForm" @ok="modalFormOk"></report-cron-job-data-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import moment from 'moment'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ReportCronJobDataModal from './modules/ReportCronJobDataModal'

export default {
  name: 'ReportCronJobDataList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ReportCronJobDataModal,
  },
  data() {
    return {
      description: '报表定时任务数据管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        // {
        //   title:'定时任务设置id',
        //   align:"center",
        //   dataIndex: 'paramId'
        // },
        {
          title: '计算日期',
          align: 'center',
          dataIndex: 'calcDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '报表id',
          align: 'center',
          dataIndex: 'reportId',
        },
        {
          title: '报表名称',
          align: 'center',
          dataIndex: 'reportName',
        },
        {
          title: '创建日期',
          align: "center",
          dataIndex: 'createTime',
          width: 60,
        },
        {
          title: '下载',
          align: 'center',
          dataIndex: 'fileUrl',
          scopedSlots: { customRender: 'fileSlot' },
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align:"center",
        //   fixed:"right",
        //   width:147,
        //   scopedSlots: { customRender: 'action' }
        // }
      ],
      url: {
        list: '/reportCronJobData/reportCronJobData/list',
        delete: '/reportCronJobData/reportCronJobData/delete',
        deleteBatch: '/reportCronJobData/reportCronJobData/deleteBatch',
        exportXlsUrl: '/reportCronJobData/reportCronJobData/exportXls',
        importExcelUrl: 'reportCronJobData/reportCronJobData/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 5,
        pageSizeOptions: ['5', '10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
       // 查询参数
      queryParam: {   },
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'paramId', text: '定时任务设置id', dictCode: '' })
      fieldList.push({ type: 'int', value: 'reportId', text: '报表id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'reportName', text: '报表名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'fileUrl', text: '文件', dictCode: '' })
      this.superFieldList = fieldList
    },
    downloadFile(text) {
      if (!text) {
        this.$message.warning('未知的文件')
        return
      }
      if (text.indexOf(',') > 0) {
        text = text.substring(0, text.indexOf(','))
      }
      let url = window._CONFIG['domianURL'] + '/sys/common/download/' + text
      window.open(url)
    }, 
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>